<template>
    <div>
        <input type="text"
               class="k-input-hidden"
               :required="required"
               :value="c"/>
        <el-radio-group :value="dValue"
                        @input="onChangeValue">
            <el-radio v-for="opt in options"
                      :key="opt.value"
                      :label="opt.value"
            >
                {{ opt.text }}
            </el-radio>
        </el-radio-group>
    </div>
</template>

<script>
export default {
    name: 'KRadio',
    props: {
        value: [String, Number, Array],
        defaultValue: [String, Number, Array],
        required: Boolean,
        options: Array,
    },
    computed: {
        dValue() {
            if (this.value) {
                return this.value;
            }
            return this.defaultValue;
        },
        c: {
            get() {
                return this.value;
            },
            set(val) {
                this.$emit('input', val);
            }
        }
    },
    methods: {
        // 值修改
        onChangeValue(value) {
            this.$emit('input', value);
        }
    }
}
</script>
